package com.yf.course.modules.course.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.course.modules.course.dto.request.CourseSpeechReqDTO;
import com.yf.course.modules.course.dto.request.CourseVideoReqDTO;
import com.yf.course.modules.course.entity.Speech;
import com.yf.course.modules.course.entity.Video;
import com.yf.course.modules.course.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频控制器
 * </p>
 */
@Api(tags = {"课程视频"})
@RestController
@RequestMapping("/api/course/video")
public class CourseVideoController extends BaseController {
    @Autowired
    private VideoService videoService;

    /**
     * 添加或修改视频
     * @param courseVideoReqDTO 请求参数
     */
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody CourseVideoReqDTO courseVideoReqDTO) {
        Boolean result = videoService.save(courseVideoReqDTO);
        if (result) {
            return super.success();
        } else {
            return super.failure("添加或修改失败");
        }
    }

    /**
     * 删除视频
     * @param videoId 视频ID
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ApiRest delete(@RequestParam(value = "videoId") String videoId) {
        Boolean result = videoService.delete(videoId);
        if (result) {
            return super.success();
        } else {
            return super.failure("删除失败");
        }
    }

    /**
     * 根据Id获取视频
     * @param videoId 视频ID
     */
    @ApiOperation(value = "根据Id获取视频")
    @PostMapping("/selectById")
    public ApiRest<Video> selectById(@RequestParam(value = "videoId") String videoId) {
        Video video = videoService.getById(videoId);
        return super.success(video);
    }

    /**
     * 分页获取视频
     * @param reqDTO 分页参数
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<Video>> paging(@RequestBody PagingReqDTO<CourseVideoReqDTO> reqDTO) {
        IPage<Video> page = videoService.paging(reqDTO);
        return super.success(page);
    }
}
